<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('网点建档新型农业主体列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>机构名称：</label>
                            <input name="deptId" type="hidden" id="treeId"/>
                            <input name="deptName" onclick="selectDeptTree()" id="treeName" type="text"
                                   placeholder="请选择归属机构" autocomplete="off">
                        </li>

                        <li class="select-date">
                            <label>建档时间：</label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间" readonly
                                   name="params[startDate]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间" readonly
                                   name="params[endDate]"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-warning" onclick="$.table.exportExcel()"
               shiro:hasPermission="merchant:branchAgriculture:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var overtimeFlag = [[${@permission.hasPermi('merchant:agrOvertimeNotVisit:list')}]];
    var prefix = ctx + "merchant/branchAgriculture";

    $(function () {
        var options = {
            url: prefix + "/list",
            exportUrl: prefix + "/export",
            modalName: "网点建档农业信息",
            columns: [
                {
                    title: '序号',
                    align: "center",
                    formatter: function (value, row, index) {
                        return index+1;
                    }
                },
                {
                    field: 'deptName',
                    title: '机构名称'
                },

                {
                    field: 'merchantNum',
                    title: '建档农业数量',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return $.table.formatNumber(value);
                    }
                },
                {
                    field: 'merchantNumUnuse',
                    title: '已停用农业数量',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return $.table.formatNumber(value);
                    }
                },
                {
                    field: 'visitSum',
                    title: '拜访次数',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return $.table.formatNumber(value);
                    }
                },
                {
                    field: 'doTaskSum',
                    title: '超时拜访次数',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return $.table.formatNumber(value);
                    }
                },
                {
                    field: 'undoTaskSum',
                    title: '超时未拜访任务',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return $.table.formatNumber(value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + overtimeFlag + '" href="javascript:void(0)" onclick="overtimeNotVisit(\'' + row.deptId + '\')"><i class="fa fa-edit"></i>超时未拜访明细</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /* 选择机构树 */
    function selectDeptTree() {
        var treeId = $("#treeId").val();
        var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
        var url = ctx + "system/dept/selectDeptTree/" + deptId;
        var options = {
            title: '选择部门',
            width: "380",
            url: url,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    //超时未拜访明细
    function overtimeNotVisit(deptId) {
        var url = prefix + '/agrOvertimeNotVisit/' + deptId;
        $.modal.openTab("超时未拜访明细", url);
    }

    function doSubmit(index, layero) {
        var body = $.modal.getChildFrame(index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        $.modal.close(index);
    }

    function reset() {
        $('#treeId').val('')
        $.form.reset();
    }
</script>
</body>
</html>